import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import { home, showlist, error404, main, login, shuoshuo } from '@/view'
const router = new VueRouter({
  routes: [
    {
      path: "/",
      component: main,
      children: [
        {
          path: '',
          component: home,
          meta: { title: "工作平台", index: "0" }
        },
        {
          path: "/showlist",
          meta: { title: "用户列表", index: "1-1" },
          component: showlist
        },
        {
          path: "/shuoshuo",
          meta: { title: "说说管理", index: "2-1" },
          component: shuoshuo
        }
      ]
    },
    {
      path: "/login",
      meta: { title: "登录" },
      component: login
    }, {
      path: "*",
      component: error404
    }

  ]
})

export default router
import config from '@/config'
router.beforeEach((to, from, next) => {
  if (to.meta && to.meta.title)
    document.title = to.meta.title + " Blued - 在这里，发现爱"

  if (to.fullPath !== '/login') {
    if (!sessionStorage.getItem(config.KEY.CACHE_LOGIN_USER)) {
      return next("/login")
    }
  }
  next()
})